from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
import unittest

class xiaoshuo(unittest.TestCase):
    def setUp(self) -> None:
        self.driver=webdriver.Edge()
        self.driver.maximize_window()
        self.driver.get('https://www.xxsypro.com/category')
    def tearDown(self) -> None:
        self.driver.quit()
        sleep(5)

    #按指定条件筛选，筛选成功
    def test_01_xiaoshuo(self):
        #点击状态
        self.driver.find_element(By.XPATH,'//*[@id="app"]/div/div[2]/div/div[2]/div[1]/div/div[1]/div[2]/a[2]').click()
        sleep(2)
        #点击属性
        self.driver.find_element(By.XPATH,'//*[@id="app"]/div/div[2]/div/div[2]/div[1]/div/div[2]/div[2]/a[2]').click()
        sleep(2)
        #点击20-30W
        self.driver.find_element(By.XPATH,'//*[@id="app"]/div/div[2]/div/div[2]/div[1]/div/div[4]/div[2]/a[3]').click()
        sleep(2)
        #点击综合热度
        self.driver.find_element(By.LINK_TEXT,'综合热度').click()
        sleep(2)
        #点击古代言情
        self.driver.find_element(By.PARTIAL_LINK_TEXT,'古代言情').click()
        sleep(2)

    # 搜索框搜索正确书名，搜索成功
    def test_02_xiaoshuo(self):
        #搜索框输入
        self.driver.find_element(By.XPATH,'//*[@id="app"]/div/div[1]/div[1]/div/form/div/input').send_keys('灯花笑')
        sleep(4)
        #点击搜索
        self.driver.find_element(By.CLASS_NAME,'submit-search').click()
        sleep(2)
        #点击书籍
        self.driver.find_element(By.XPATH,'//*[@id="app"]/div/section/div[1]/a[1]/div[2]').click()
        sleep(2)

    #输入错误的跳转页码，跳转失败，提示请输入正确的页码
    def test_03_xiaoshuo(self):
        #向下滚动到底部
        self.driver.execute_script('window.scrollTo(0,document.body.scrollToHeight)')
        sleep(4)
        #输入页码
        self.driver.find_element(By.XPATH,'//*[@id="app"]/div/div[2]/div/div[2]/div[2]/div[2]/input').clear()
        sleep(5)
        self.driver.find_element(By.XPATH,'//*[@id="app"]/div/div[2]/div/div[2]/div[2]/div[2]/input').send_keys('60')
        sleep(5)
        #点击Go
        self.driver.find_element(By.CLASS_NAME,'pagination-jump').click()
        sleep(5)


#执行
if __name__ == '__main__':
    unittest.main()